//
//  WWMeView.m
//  Shopping
//
//  Created by 张湾湾 on 16/8/20.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWMeView.h"


#import "WWButton.h"

#import "WWMeView.h"
#import "WWTopViewCell.h"
@interface WWMeView() <UITableViewDataSource,UITableViewDelegate>
/**头像*/
@property (nonatomic,weak)WWButton *iconButton;

/**设置*/
@property (nonatomic,weak)UIButton *setButton;

@property (nonatomic,strong)NSArray *imageArray;

@property (nonatomic,strong)NSArray *nameArray;


@end

@implementation WWMeView

#pragma mark - 控制器 -
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    if (self = [super initWithFrame:frame style:UITableViewStyleGrouped]) {
        self.rowHeight = 60;
        self.delegate = self;
        self.dataSource = self;
        [self setupUI];
        
        [self registerClass:[WWTopViewCell class] forCellReuseIdentifier:@"cell1"];
    }
    return self;
}

#pragma mark - 页面 -
- (void)setupUI{
    self.sectionHeaderHeight = 10;
    self.tableHeaderView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"v2_my_avatar_bg"]];
    [self.iconButton makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.tableHeaderView);
    }];
    [self.setButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(15);
        make.trailing.equalTo(-30);
        make.size.equalTo(CGSizeMake(30, 30));
    }];
    
}
#pragma mark - 代理 -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    NSArray * array = self.imageArray[section];
    return array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 && indexPath.row == 0) {
        WWTopViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        return cell;
    }else{
   
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        //取值
        NSArray * array = self.imageArray[indexPath.section];
        cell.imageView.image = [UIImage imageNamed:array[indexPath.row]];
        //text
        NSArray * nameArray = self.nameArray[indexPath.section];
        cell.textLabel.text = nameArray[indexPath.row];
    }
    return cell;
    }
}
- (WWButton *)iconButton{
    if (!_iconButton) {
        WWButton * button = [[WWButton alloc]init];
        [button setImage:[UIImage imageNamed:@"v2_my_avatar"] forState:UIControlStateNormal];
        //        [button setTitle:@"1234" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15];
        _iconButton = button;
        [self.tableHeaderView addSubview:button];
    }
    return _iconButton;
}
- (UIButton *)setButton{
    if (!_setButton) {
        UIButton * btn = [UIButton new];
        [btn setImage:[UIImage imageNamed:@"v2_my_settings_icon"] forState:UIControlStateNormal];
        _setButton = btn;
        [self.tableHeaderView addSubview:btn];
    }
    return _setButton;
}

#pragma mark - 添加图片 -
- (NSArray*)imageArray{
    if (!_imageArray) {
        _imageArray = @[@[@""],@[@"v2_my_address_icon",@"icon_mystore"],@[@"v2_my_share_icon",@"v2_my_serviceonline_icon"],@[@"v2_my_feedback_icon"]];
    }
    return _imageArray;
}
- (NSArray *)nameArray{
    if (!_nameArray) {
        _nameArray = @[@[@""],@[@"我的收获地址",@"我的店铺"],@[@"把爱鲜蜂分享给朋友",@"客服帮助"],@[@"意见反馈"]];
    }
    return _nameArray;
}
@end
